/*
 * Author: http://www.redwolf-soft.com
 * All Rights Reserved
 * 
 * 2013.11
 *   
 * */
package com.redwolfsoft.libshoppingserver.brand;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/*
 * 
 ne 
 * */

public class NewProductInfo {
	public final static String TAG = "NewProductInfo";
	public String id =null;
	
	public String mDisplayName = null;	//新品要在客户端显示的名称	
	public String picUrlStr = null;//新品图片链接
	public String picFileName = null;//新品图片文件名称	
	public String picFilePath = null;//新品图片保存路径
	
	public String bigPicUrlStr = null;
	public String bigPicFileName = null;
	public String bigPicFilePath = null;
	
	public int numReviews = 0;
	public int numApplaud = 0;
	public boolean hasApplauded=false;
	public List<PriceInfo> priceList = new ArrayList<PriceInfo>();
	
	/**
	 * 对服务器端而言，图片路径picFilePath，bigPicFilePath无意义，可指定为空值
	 * 服务端，除了调用此构造函数赋值外，还要对其它字段赋初值
	 * */
	public NewProductInfo(String id, String name,
			String url,String filepath,String filename,
			int numReviews, int numApplaud,
			String bigPicUrl,String bigPicFileName)
	{
		this.id =id;
		mDisplayName = name;
		picUrlStr = url;	
		picFileName = filename;
		picFilePath = filepath;
		
		this.numReviews = numReviews;
		this.numApplaud = numApplaud;
		bigPicUrlStr = bigPicUrl;
		this.bigPicFileName = bigPicFileName;
		bigPicFilePath = picFilePath;
	}
	
	public NewProductInfo(JSONObject obj)
	{
		if(obj==null)
		{
			//Log.w(TAG, "JSONObject is null");
			return;
		}
		//try {		
			id = obj.getString("id");
			mDisplayName = obj.getString("mDisplayName");
			
			picUrlStr = obj.getString("picUrlStr");	
			picFileName = obj.getString("picFileName");
			picFilePath = obj.getString("picFilePath");	
			
			bigPicUrlStr = obj.getString("bigPicUrlStr");
			bigPicFileName = obj.getString("bigPicFileName");
			bigPicFilePath = obj.getString("bigPicFilePath");
			
			numReviews = obj.getInt("numReviews");
			numApplaud = obj.getInt("numApplaud");
			hasApplauded = obj.getBoolean("hasApplauded");
			
			priceList = new ArrayList<PriceInfo>();
			JSONArray array1 = obj.getJSONArray("priceList");
			for(int i=0;i<array1.size();i++)
			{				
				priceList.add(new PriceInfo(array1.getJSONObject(i)));
			}
			
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}
	public JSONObject toJsonObject()
	{
		JSONObject obj = new JSONObject();
		//JSONObject obj2 = new JSONObject();
		//try {
			obj.put("id", id);
			obj.put("mDisplayName", mDisplayName);
			obj.put("picUrlStr", picUrlStr);
			obj.put("picFileName", picFileName);
			obj.put("picFilePath", picFilePath);
			
			obj.put("bigPicUrlStr", bigPicUrlStr);
			obj.put("bigPicFileName", bigPicFileName);
			obj.put("bigPicFilePath", bigPicFilePath);
			
			obj.put("numReviews", numReviews);
			obj.put("numApplaud", numApplaud);
			obj.put("hasApplauded", hasApplauded);
			
			JSONArray array1 = new JSONArray();
			for(int i=0;i<priceList.size();i++)
			{
				array1.add(i,priceList.get(i).toJsonObject());
			}
			obj.put("priceList", array1);			
			
			
			//obj2.put(TAG, obj);
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}*/
		return obj;
		
	}
}
